package com.hien.starting;

import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

public class FoolTabActivity extends TabActivity {
	private TabHost tabHost;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tab_indicator);
		tabHost = getTabHost();
		tabHost.getTabWidget().setDividerDrawable(R.drawable.divider);
		setTab();
		Bundle extras= getIntent().getExtras();
	if(extras!=null){
		int state  = extras.getInt(HomeActivity.STATE);
		if(state > 0 ) tabHost.setCurrentTab(state);
	}
		
	}

	private void setTab() {
		addTab(tabHost, "Home", "Home", R.drawable.tab_home_selector,
				new Intent(this, HomeActivity.class));
		addTab(tabHost, "Tips", "Tips", R.drawable.tab_tip_selector,
				new Intent(this, TipsActivity.class));
		addTab(tabHost, "Donkey", "Donkey", R.drawable.tab_donkey_selector,
				new Intent(this, DonkeyActivity.class));
		addTab(tabHost, "Infor", "Infor", R.drawable.tab_info_selector,
				new Intent(this, InforActivity.class));
		tabHost.setCurrentTab(1);
	}

	private void addTab(TabHost host, String name, String tag, int drawable,
			Intent intent) {
		TabHost.TabSpec spec = host.newTabSpec(tag);
		spec.setContent(intent);
		View view = createTabView(host.getContext(), name, drawable);
		spec.setIndicator(view);
		host.addTab(spec);
	}

	private static View createTabView(Context context, String name, int imgRes) {
		View view = LayoutInflater.from(context).inflate(R.layout.tab_layout,
				null);
		ImageView imageView = (ImageView) view.findViewById(R.id.tab_icon);
		TextView tv = (TextView) view.findViewById(R.id.tab_name);
		imageView.setBackgroundResource(imgRes);
		tv.setText(name);
		return view;
	}

}
